package com.jxtti.controller;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.jxtti.entity.TDocDocumentsrelease;
import com.jxtti.service.TDocDocumentsreleaseService;
import com.jxtti.utils.ExceptionUtil;
/**
 * 
 * <br>
 * <b>功能：</b>TDocDocumentsreleaseController<br>
 * <b>作者：lwb</b><br>
 * <b>日期：</b> Nov 26, 2015 <br>
 * <b>版权所有：<b>版权所有(C) 2015，<br>
 */ 
@Controller
@RequestMapping("/tDocDocumentsrelease") 
public class TDocDocumentsreleaseController {
	
	private final static Logger log= Logger.getLogger(TDocDocumentsreleaseController.class);
	
	// Servrice start
	@Autowired
	private TDocDocumentsreleaseService  tDocDocumentsreleaseService; 
	
	
	
	
	
	/**
	 * 
	 * @param url
	 * @param classifyId
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping(value="/list") 
	public ModelAndView  list(@RequestParam Map<String, Object> data,  TDocDocumentsrelease tDocDocumentsrelease, HttpServletRequest request,
			HttpServletResponse response) throws Exception{		
		ModelAndView mav = new ModelAndView();
		try {
			data =  tDocDocumentsreleaseService.list(data, tDocDocumentsrelease);
			mav.addObject("data", data);
			mav.setViewName("jxtti/com.jxtti/tDocDocumentsrelease");
		} catch (Exception e) {
			e.printStackTrace();
			
		}
		return mav;
	}
	
	
	
	/**
	 * 点击添加跳转到增加界面
	 * 
	 * @param data
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/addInterface")
	@ResponseBody
	public ModelAndView addInterface(@RequestParam Map<String, Object> data,
			HttpServletRequest request, HttpServletResponse response) {
		ModelAndView mav = new ModelAndView();
		try {
			mav.addObject("data", data);
			mav.setViewName("/pages/tDocDocumentsrelease/add.jsp");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return mav;
	}
	
	
	
	
	/**
	 * 添加或修改数据
	 * @param url
	 * @param classifyId
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping(value = "/save")
	@ResponseBody
	public Map<String,Object> save(@RequestParam Map<String, Object> data,
			TDocDocumentsrelease  tDocDocumentsrelease, HttpServletRequest request,
			HttpServletResponse response) throws Exception{

		ModelAndView mav = new ModelAndView();
		try {
			// 保存数据
			//User user = AuthUtil.getUserInfo(request);
			//disStandard.setOperPerson(user.getUserName());
			int exeCount = tDocDocumentsreleaseService.add(tDocDocumentsrelease);
			if (exeCount > 0) {
				data.put("success", true);
			} else {
				data.put("success", false);
			}
		} catch (Exception e) {
			data.put("success", false);
			data.put("error", ExceptionUtil.createStackTrackMessage(e));
			e.printStackTrace();
		}
		return data;
	}
	
	
	
	
	/**
	 * 点击修改跳转到增加界面
	 * 
	 * @param data
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/updateInterface")
	@ResponseBody
	public ModelAndView updateInterface(@RequestParam Map<String, Object> data,
			HttpServletRequest request, TDocDocumentsrelease  tDocDocumentsrelease,
			HttpServletResponse response) {
		ModelAndView mav = new ModelAndView();
		try {
			tDocDocumentsrelease = tDocDocumentsreleaseService.queryTDocDocumentsreleaseById(tDocDocumentsrelease);
		
			data.put("tDocDocumentsrelease", tDocDocumentsrelease);
			mav.addObject("data", data);
			mav.setViewName("/pages/tDocDocumentsrelease/update.jsp");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return mav;
	}
	
	
	
	
	
	
	
	/**
	 * 修改信息
	 * 
	 * @param data
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> update(@RequestParam Map<String, Object> data,
			TDocDocumentsrelease  tDocDocumentsrelease, HttpServletRequest request,
			HttpServletResponse response) {
		try {
		//	User user = AuthUtil.getUserInfo(request);
		//	tDocDocumentsrelease.setOperPerson(user.getUserName());
			// 修改
			TDocDocumentsrelease tDocDocumentsreleaseTem=tDocDocumentsreleaseService.queryTDocDocumentsreleaseById(tDocDocumentsrelease);
			
			
			int exeCount = tDocDocumentsreleaseService.update( tDocDocumentsrelease);
			if (exeCount > 0) {
				data.put("success", true);
			} else {
				data.put("success", false);
			}
		} catch (Exception e) {
			data.put("success", false);
			data.put("error", ExceptionUtil.createStackTrackMessage(e));
			e.printStackTrace();
		}
		return data;
	}
	
	

/**
	 * 删除信息
	 * 
	 * @param data
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/delete")
	@ResponseBody
	public Map<String, Object> delete(@RequestParam Map<String, Object> data,
			TDocDocumentsrelease  tDocDocumentsrelease, HttpServletRequest request,
			HttpServletResponse response) {
		try {
		//	User user = AuthUtil.getUserInfo(request);
		//	tDocDocumentsrelease.setOperPerson(user.getUserName());
		
			 tDocDocumentsrelease=tDocDocumentsreleaseService.queryTDocDocumentsreleaseById( tDocDocumentsrelease);
			int exeCount = tDocDocumentsreleaseService.update(tDocDocumentsrelease);
			if (exeCount > 0) {
				data.put("success", true);
			} else {
				data.put("success", false);
			}
		} catch (Exception e) {
			data.put("success", false);
			data.put("error", ExceptionUtil.createStackTrackMessage(e));
			e.printStackTrace();
		}
		return data;
	}

}
